package cn.sycoder.mapper;

import cn.sycoder.entity.LoginRecords;
import cn.sycoder.vo.LoginRecordsVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 杨润发
 * @since 2024-11-01
 */
@Repository
public interface LoginRecordsMapper extends BaseMapper<LoginRecords> {

    @Select("SELECT " +
            "user_name,count(user_name) " +
            "FROM login_records " +
            "GROUP BY user_name " +
            "ORDER BY count(user_name) " +
            "DESC limit 5")
    @Results({
            @Result(property = "userName", column = "user_name"),
            @Result(property = "count", column = "count(user_name)") // 指定数据库返回结果对应列名
    })
    List<LoginRecordsVo> select();
}
